package com.why.simpleboot.core.core.factory;

import com.why.simpleboot.core.annotation.aop.Aspect;
import com.why.simpleboot.core.annotation.ioc.Component;
import com.why.simpleboot.core.annotation.mvc.RestController;
import com.why.simpleboot.core.common.utils.SimpleReflectUtils;

import java.lang.annotation.Annotation;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: why-simpleboot-framework
 * @description:负责扫描缓存被注解标注的类
 * @author: @why
 * @create: 2021-05-22 17:13
 **/
public class ClassFactory implements Factory {
    /**
     * 缓存类，  key---->注解：value--->Classes文件
     */
    private final ConcurrentHashMap<Class<? extends Annotation>, Set<Class<?>>> CLASSES = new ConcurrentHashMap<>(128);

    public void loadClasses(String... basePackages) {
        Set<Class<?>> components = SimpleReflectUtils.getClassesByAnnotation(Component.class, basePackages);
        Set<Class<?>> controllers = SimpleReflectUtils.getClassesByAnnotation(RestController.class, basePackages);

        Set<Class<?>> aspects = SimpleReflectUtils.getClassesByAnnotation(Aspect.class, basePackages);
        CLASSES.put(RestController.class, controllers);
        CLASSES.put(Component.class, components);
        CLASSES.put(Aspect.class, aspects);
    }

    public ConcurrentHashMap<Class<? extends Annotation>, Set<Class<?>>> getCLASSES() {

        return CLASSES;
    }
}
